import storage from './storage'
import api from '../http/api'
export default{
  /**
   * 登录
   */
  updataUserInfo(){
    return new Promise(function (resolve, reject){
      wx.login({
        complete: (loginRes) => {
          /**
           * 获取用户信息
           */
          wx.getUserInfo({
            complete: (userInfoRes) => {
              /**
               * 储存用户信息
               */
              storage.setUserInfo(userInfoRes)
              userInfoRes.userInfo.jsCode=loginRes.code
              userInfoRes.userInfo.openId=storage.getOpenId();
              /**
               * 更新用户
               */
              api.updataUserInfo(userInfoRes.userInfo).then((res)=>{
                storage.setGlobalData(res.data)
                resolve(res.data)
              })
            },
          })
        },
      })
     
    })
  },
  author(auth,callback){
    wx.getSetting({
      success (res) {
        callback(res.authSetting)
      }
    })
  }

}